clear all

// SET MACROS
global Input  "Y:/limited/Michigan_CTE/funding_change/data_final"
global Output "Y:/limited/Michigan_CTE/funding_change/output/figures"

qui include "Y:/limited/Michigan_CTE/funding_change/code/analyze/figures/00_colors.do"

local demographics "female black hisp another_race sped lep econdis"
local academics "test_avg_g8 test_avg_sq_g8 test_avg_g8_imp attendance_g8 attendance_g8_imp"

// LOAD DATA
use $Input/compiled_student_analysis_data.dta

keep if grad_year >= 2012 
keep if max_courses > 0
gen post = grad_year >= 2015

gen all = 1

tab max_segment post
gen seg_bin = 4
replace seg_bin = 9 if max_segment > 6
replace seg_bin = 14 if max_segment > 11
replace seg_bin = 19 if max_segment > 12

gen course_bin = max_courses
replace course_bin = 4 if max_courses > 4

bys post course_bin: gegen denominator = total(all)

gcollapse (sum) all (mean) denominator, by(seg_bin course_bin post )
replace all = all / denominator 

gen n0 = seg_bin - 0.5
gen n1 = seg_bin + 0.5

bys course_bin post : gegen share = total(all)

local pci "(pci 1 6.5 -.1 6.5, lcolor(gs11)) (pci 1 11.5 -.1 11.5, lcolor(gs11)) (pci -.06 1.6 -.06 6.4, lcolor(gs3)) (pci -.06 6.6 -.06 11.4, lcolor(gs3)) (pci -.06 11.6 -.06 20.4, lcolor(gs3))"

local text `"text(-.06 4 " Partic. ", bc(white) box) text(-.06 9 " Concen. ", bc(white) box) text(-.06 16.5 " Completers ", bc(white) box)"'

// DRAW GRAPH - ONE COURSE
tw `pci' ///
   (bar all n0 if post == 0 & course_bin == 1, barw(1) color("$c1")) ///
   (bar all n1 if post == 1 & course_bin == 1, barw(1) color("$c2")) ///
   (pci 0 1.5 0 20.5, color(black) lw(.25)), ///
   scale(1.4) ///
   `text' ///
   ytitle("Share of Students") ///
   xtitle("Segments Completed in Main CTE Program", margin(t=1)) ///
   xlabel(4 "0-6" 9 "7-11" 14 "12" 19 "Q") ///
   xscale(r(1.5 20.5)) ///
   ylabel(0 "0" 0.2 "0.2" 0.4 "0.4" 0.6 "0.6" 0.8 "0.8" 1 "1.0", angle(0) nogrid) ///
   yscale(r(-0.025 0.15)) ///
   legend(order(6 "Before Change" 7 "After Change") symxsize(7) region(lstyle(none))) ///
   graphregion(color(white)) bgcolor(white) ///
   xsize(3) ysize(2.25) ///
	 scheme(s2color)

// EXPORT GRAPH


graph save $Output/04a_segments_one_course.gph, replace
*graph export $Output/segments_one_course.png, replace

// DRAW GRAPH - TWO COURSES
tw `pci' ///
   (bar all n0 if post == 0 & course_bin == 2, barw(1) color("$c1")) ///
   (bar all n1 if post == 1 & course_bin == 2, barw(1) color("$c2")) ///
   (pci 0 1.5 0 20.5, color(black) lw(.25)), ///
   scale(1.4) ///
   `text' ///
   ytitle("Share of Students") ///
   xtitle("Segments Completed in Main CTE Program", margin(t=1)) ///
   xlabel(4 "0-6" 9 "7-11" 14 "12" 19 "Q") ///
   xscale(r(1.5 20.5)) ///
   ylabel(0 "0" 0.2 "0.2" 0.4 "0.4" 0.6 "0.6" 0.8 "0.8" 1 "1.0", angle(0) nogrid) ///
   yscale(r(-0.025 0.15)) ///
   legend(order(6 "Before Change" 7 "After Change") symxsize(7) region(lstyle(none))) ///
   graphregion(color(white)) bgcolor(white) ///
   xsize(3) ysize(2.25) ///
	 scheme(s2color)

// EXPORT GRAPH
graph save $Output/04b_segments_two_courses.gph, replace
*graph export $Output/segments_two_courses.png, replace

// DRAW GRAPH - THREE COURSES
tw `pci' ///
   (bar all n0 if post == 0 & course_bin == 3, barw(1) color("$c1")) ///
   (bar all n1 if post == 1 & course_bin == 3, barw(1) color("$c2")) ///
   (pci 0 1.5 0 20.5, color(black) lw(.25)), ///
   scale(1.4) ///
   `text' ///
   ytitle("Share of Students") ///
   xtitle("Segments Completed in Main CTE Program", margin(t=1)) ///
   xlabel(4 "0-6" 9 "7-11" 14 "12" 19 "Q") ///
   xscale(r(1.5 20.5)) ///
   ylabel(0 "0" 0.2 "0.2" 0.4 "0.4" 0.6 "0.6" 0.8 "0.8" 1 "1.0", angle(0) nogrid) ///
   yscale(r(-0.025 0.15)) ///
   legend(order(6 "Before Change" 7 "After Change") symxsize(7) region(lstyle(none))) ///
   graphregion(color(white)) bgcolor(white) ///
   xsize(3) ysize(2.25) ///
	 scheme(s2color)

// EXPORT GRAPH
graph save $Output/04c_segments_three_courses.gph, replace
*graph export $Output/04c_segments_three_courses.png, replace


// DRAW GRAPH - FOUR COURSES
tw `pci' ///
   (bar all n0 if post == 0 & course_bin == 4, barw(1) color("$c1")) ///
   (bar all n1 if post == 1 & course_bin == 4, barw(1) color("$c2")) ///
   (pci 0 1.5 0 20.5, color(black) lw(.25)), ///
   scale(1.4) ///
   `text' ///
   ytitle("Share of Students") ///
   xtitle("Segments Completed in Main CTE Program", margin(t=1)) ///
   xlabel(4 "0-6" 9 "7-11" 14 "12" 19 "Q") ///
   xscale(r(1.5 20.5)) ///
   ylabel(0 "0" 0.2 "0.2" 0.4 "0.4" 0.6 "0.6" 0.8 "0.8" 1 "1.0", angle(0) nogrid) ///
   yscale(r(-0.025 0.15)) ///
   legend(order(6 "Before Change" 7 "After Change") symxsize(7) region(lstyle(none))) ///
   graphregion(color(white)) bgcolor(white) ///
   xsize(3) ysize(2.25) ///
	 scheme(s2color)

// EXPORT GRAPH

graph save $Output/04d_segments_four_courses.gph, replace
*graph export $Output/segments_four_courses.png, replace




*Numbers for text
di (1-.9035533) - (1-.8177832)
di ((1-.9035533) - (1-.8177832))/(1-.9035533)

di ((1-.4903005) - (1-.3645078))
di ((1-.4903005) - (1-.3645078))/(1-.4903005)

di (.2848771 + .0000654) - (.3694107 + .0720841)
di ((.2848771 + .0000654) - (.3694107 + .0720841))/(.2848771 + .0000654)

di .0000654 - .0720841
di (.0000654 - .0720841)/.0000654

di (.0095731- .1115511)
di (.0095731- .1115511)/.0095731

di (.0952756- .392024)
di (.0952756- .392024)/.0952756








